﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;

namespace WinFormsApp1.TongShiWei
{
    public partial class AddPigData : UIForm
    {
        public AddPigData()
        {
            InitializeComponent();
            GetPRQCData();
        }
        #region 获取检测项目下拉框数据
        List<SHowPRQCData> sHowPRQCDatas = new List<SHowPRQCData>();
        public async void GetPRQCData()
        {
            //http://localhost:5106/api/Tsw/GetIPQCData
            var res = await HttpClientHelper.RequestUrl<SHowPRQCData, ApiResult<List<SHowPRQCData>>>(URLCommon.Url2, "/Tsw/GetIPQCData", HttpClientHelper.MethodType.GET);
            if (res != null)
            {
                if (res.Code > 0)
                {
                    sHowPRQCDatas = res.Data;
                    PRQSName.DataSource = res.Data;
                    //PRQSName.ValueMember = "PRQSName";
                    PRQSName.DisplayMember = "PRQSName";
                }
            }
        }
        /// <summary>
        /// 获取检测项目下拉框数据
        /// </summary>
        public class SHowPRQCData
        {
            /// <summary>
            /// 检疫项目Id
            /// </summary>
            public int PRQSId { get; set; }
            /// <summary>
            /// 检疫项目名称
            /// </summary>
            public string PRQSName { get; set; } = string.Empty;
            /// <summary>
            /// 检疫指标
            /// </summary>
            public string PRQSindex { get; set; } = string.Empty;
            /// <summary>
            /// 标准要求
            /// </summary>
            public string Require { get; set; } = string.Empty;
            /// <summary>
            /// 启用状态
            /// </summary>
            public bool PRQSstate { get; set; } = false;
            /// <summary>
            /// 创建人
            /// </summary>
            public string CreateName { get; set; } = string.Empty;
            /// <summary>
            /// 创建时间
            /// </summary>
            public DateTime CreateTime { get; set; } = DateTime.Now;
            /// <summary>
            /// 最后修改人
            /// </summary>
            public string FinallyName { get; set; } = string.Empty;
            /// <summary>
            /// 最后修改时间
            /// </summary>
            public DateTime FinallyTime { get; set; } = DateTime.Now;
            /// <summary>
            /// 是否禁用
            /// </summary>
            public bool IsPRQS { get; set; } = false;
            /// <summary>
            /// 是否删除
            /// </summary>
            public bool ISDeletePRQS { get; set; } = false;
        }
        /// <summary>
        /// 反填检测项目数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PRQSlistData_CellValueChanged_1(object sender, DataGridViewCellEventArgs e)
        {
            if (!(e.RowIndex >= 0))
            {
                return;
            }
            var PRQSDataName = PRQSlistData.Rows[e.RowIndex].Cells[1].Value.ToString();
            var PRQSContext = sHowPRQCDatas.FirstOrDefault(x => x.PRQSName == PRQSDataName);
            if (PRQSContext != null)
            {
                PRQSlistData.Rows[e.RowIndex].Cells[0].Value = PRQSContext.PRQSId;
                PRQSlistData.Rows[e.RowIndex].Cells[2].Value = PRQSContext.PRQSindex;
                PRQSlistData.Rows[e.RowIndex].Cells[3].Value = PRQSContext.Require;
            }
        }
        #endregion


    }
}
